.DELETE_ON_ERROR:

SRCS :=                        \
	field.c                    \
	field-write.c              \
	field-laplacian.c          \
	field-laplacian_rhu.c      \
	field-laplacian_rhv.c      \
	field-nonlinear.c          \
	field-ops.c                \
	field-tension.c            \
	field-gradient.c           \
	field-divergence.c         \
	field-divergence_tenseur.c \
	field-algebra.c            \
	types.c                    \
	simulation.c               \
	sim-pressure.c             \
	sim-ops.c                  \
	sim-write.c            

OBJS := $(SRCS:.c=.o)

ALLC := $(wildcard *.c)
DEPS := $(addprefix .deps/,$(ALLC:.c=.d))


CFLAGS := -Wall
CC     := gcc

all: deps nsb 

nsb: main.o $(OBJS)
	@echo "Linking $@"
	@$(CC) -o $@ $^ -lm 

test-%: test-%.o $(OBJS)
	@echo "Linking $@"
	@$(CC) -o $@ $^ -lm 

tests : test-field test-sim test-diff
	./test-field
	./test-sim
	./test-diff

flags:
	@echo $(CFLAGS)

%.o: %.c
	@echo "Compiling $<"
	@$(CC) -c -o $@ $< $(CFLAGS)

deps: $(DEPS)

.deps/%.d: %.c
	@$(CC) -M $(CFLAGS) -o $@ $< &> /dev/null

clean:
	rm -f *~ *.o *.vtk *.vti
	rm -f .deps/*
	rm -f temp/*
	rm -f temp1/*
	rm -f *.dat
	rm -f nsb nsb.exe
	rm -f test-field test-field.exe
	rm -f test-sim   test-sim.exe
	rm -f test-diff  test-diff.exe


-include $(DEPS)

